<script setup lang="ts">
import { reactive, ref } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'

// el-form
const formRef = ref<FormInstance>()
const formData = reactive({
  username: '',
  password: '',
  remember: false,
})
const formRules = reactive<FormRules>({
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' },
    { min: 4, max: 20, message: '用户名长度在4到20字符之间', trigger: 'blur' },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 4, max: 20, message: '密码长度在4到20字符之间', trigger: 'blur' },
  ],
})

// loading
const loading = ref(false)
const login = () => {}
</script>

<template>
  <div class="form">
    <h2 class="form-title">登录系统：</h2>
    <div class="form-subtitle">
      还没有账号？
      <el-link class="form-link" type="primary" :underline="false">立即注册</el-link>
    </div>
    <!-- 表单 -->
    <el-form class="form-content" ref="formRef" label-position="top" :model="formData" status-icon :rules="formRules">
      <!-- 用户名 -->
      <el-form-item label="" prop="username">
        <el-input class="w-50 m-2" v-model="formData.username" maxlength="20" size="large"></el-input>
      </el-form-item>
      <!-- 密码 -->
      <el-form-item label="" prop="password">
        <el-input v-model="formData.password" type="password" size="large"></el-input>
      </el-form-item>
      <!-- 记住密码 忘记密码？ -->
      <el-form-item>
        <div class="form-change">
          <el-checkbox v-model="formData.remember" label="记住密码" size="large" />
          <el-link type="primary" :underline="false">忘记密码？</el-link>
        </div>
      </el-form-item>
      <!-- 登录 -->
      <el-form-item>
        <el-button class="form-button" color="#626aef" size="large" :loading="loading" @click="login">登录</el-button>
      </el-form-item>
    </el-form>
    <!-- 第三方登录 -->
    <div class="form-third">
      <el-tooltip content="企业微信登录" effect="light" placement="top">
        <i class="iconfont icon-qiyeweixin1" />
      </el-tooltip>
      <el-tooltip content="钉钉登录" effect="light" placement="top">
        <i class="iconfont icon-dingding" />
      </el-tooltip>
      <el-tooltip content="支付宝登录" effect="light" placement="top">
        <i class="iconfont icon-zhifubao" />
      </el-tooltip>
    </div>
  </div>
</template>

<style lang="less" scoped>
.form {
  flex-grow: 1;
  padding: 50px 20px;
  background-color: #fff;
}
.form-title,
.form-subtitle,
.form-subtitle :deep(.el-link__inner) {
  font-weight: 600;
}
.form-subtitle {
  font-weight: 600;
}
.form-content {
  margin-top: 40px;
}
.form-change {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}
.form-button {
  width: 100%;
}
// 第三方
.form-third {
  width: 100%;
  display: flex;
  justify-content: center;
  i {
    font-size: 30px;
    cursor: pointer;
    & + i {
      margin-left: 20px;
    }
    &.icon-dingding {
      color: #00a5fd;
    }
    &.icon-zhifubao {
      color: #027aff;
    }
    &.icon-qiyeweixin1 {
      color: #0082ef;
    }
  }
}

:deep(.el-form-item) {
  margin-bottom: 40px;
}
</style>
